<?php include "./pc/view/header.inc.htm"; ?>

<div class="panel">
	<div class="header">设置密码</div>
	<div class="body">
		<div style="width: 300px; margin: auto;">
			<form method="POST" id="form" action="user-setpw.htm" class="form">
				<p><?php echo $email; ?></p>
				<p><input type="password" placeholder="新密码" name="password" style="width: 100%;"></p>
				<p><input type="password" placeholder="重复密码" name="password2" style="width: 100%;"></p>
				<dl class="row margin">
					<dt><button type="submit" loading-text="正在提交..." class="blue big" style="width: 100px;">完成注册</button></dt>
				</dl>			
			</form>
		</div>
	</div>
</div>

<?php include "./pc/view/footer.inc.htm"; ?>

<script>

var referer = $.pdata('referer');
if(!referer) referer = './';

var jform = $('#form');
var jsubmit = jform.find('button[type="submit"]');
var jpassword = jform.find('input[name="password"]');
var jpassword2 = jform.find('input[name="password2"]');
jform.off('submit').on('submit', function() {
//jsubmit.off('click').on('click', function() {
	if(!jpassword.val()) {
		jpassword.popover('请输入密码').focus();
		return false;
	}
	if(jpassword.val() != jpassword2.val()) {
		jpassword2.popover('两次输入的密码不一致').focus();
		return false;
	}
	var postdata = {password: $.md5(jpassword.val())};
	jsubmit.button('loading');
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			jsubmit.button('注册成功');
			setTimeout(function() { window.location=referer; }, 2000);
		} else if(code == 1) {
			jpassword.popover(message).focus();
			jsubmit.button('reset');
		} else {
			$.alert(message);
			setTimeout(function() {jsubmit.button('reset');}, 1000);
		}
	});
	return false;
});
</script>